package com.java46.admin.order.action;


import com.java46.admin.base.action.BaseAction;
import com.java46.admin.base.exception.BusinessException;


import com.java46.admin.dessertType.service.DessertTypeService;
import com.java46.admin.order.entity.AllOrders;
import com.java46.admin.order.entity.OrderInfoAndDessert;
import com.java46.admin.order.service.OrderService;

import com.java46.admin.user.util.Page;
import com.java46.front.dessertType.entity.DesserttypeEntity;
import com.java46.front.order.entity.OrdersEntity;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import java.util.List;

public class OrderAction extends BaseAction {
    private String pageNo;
    private String condition;
    private String orderId;
    public String getOrderId() {
        return orderId;
    }
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    public String getPageNo() {
        return pageNo;
    }
    public void setPageNo(String pageNo) {
        this.pageNo = pageNo;
    }
    public String getCondition() {
        return condition;
    }
    public void setCondition(String condition) {
        this.condition = condition;
    }
    private OrderService orderService= new OrderService();
    //查询
    @Action(value="getAllOrders",results = {
            @Result(name="success",location="/detail/orderList.jsp")
    })
    public String getAllOrders(){
        if(condition!=null){
            request.setAttribute("condition",condition);
        }
       Page page = orderService.getAllOrders(pageNo, condition);
        if (page.getList()==null){
            throw new BusinessException("天啊数据被外星人劫持啦...");
        }
        request.setAttribute("page", page);
        return "success";
    }

    //删除
    @Action(value="removeOrders",results = {
            @Result(type = "chain",name="success",location="getAllOrders")
    })
    public String removeOrders(){
        orderService.deleteOrders(orderId);
        return "success";
    }
    //订单详情信息
    @Action(value="getOrderInfo",results = {
            @Result(name="success",location="/detail/orderDetail.jsp")
    })
    public String getOrderInfo(){
        AllOrders orders = orderService.getOrdersByOrderId(orderId);
        if(orders==null){
            throw new BusinessException("天啊数据被外星人劫持啦...");
        }
        List<OrderInfoAndDessert> orderInfoList = orders.getOrderInfos();
        request.setAttribute("orders",orders);
        request.setAttribute("list",orderInfoList);
        return "success";
    }
}
